package com.carter.springframework.beans.factory.support;

import com.carter.springframework.beans.factory.config.CarterBeanDefinition;
import com.carter.springframework.util.ObjectUtils;
import com.sun.istack.internal.Nullable;

public class GenericBeanDefinition extends AbstractBeanDefinition{
    private String parentName;

    public GenericBeanDefinition() {
        super();
    }

    /**
     * Create a new GenericBeanDefinition as deep copy of the given
     * bean definition.
     * @param original the original bean definition to copy from
     */
    public GenericBeanDefinition(CarterBeanDefinition original) {
        super(original);
    }

    @Override
    public AbstractBeanDefinition cloneCarterBeanDefinition() {
        return null;
    }

    @Override
    public void setParentName(@Nullable String parentName) {
        this.parentName = parentName;
    }

    @Override
    @Nullable
    public String getParentName() {
        return this.parentName;
    }

    @Override
    public CarterBeanDefinition getOriginatingBeanDefinition() {
        return null;
    }

    @Override
    public boolean equals(@Nullable Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof GenericBeanDefinition)) {
            return false;
        }
        GenericBeanDefinition that = (GenericBeanDefinition) other;
        return (ObjectUtils.nullSafeEquals(this.parentName, that.parentName) && super.equals(other));
    }

    @Override
    public String toString() {
        if (this.parentName != null) {
            return "Generic bean with parent '" + this.parentName + "': " + super.toString();
        }
        return "Generic bean: " + super.toString();
    }
}
